package com.tangyuan.user.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tangyuan.common.constant.RedisConstant;
import com.tangyuan.common.result.Result;
import com.tangyuan.common.util.DateUtil;
import com.tangyuan.dto.UserHonouredGuestDto;
import com.tangyuan.model.User;
import com.tangyuan.model.activity.HonouredGuest;
import com.tangyuan.user.mapper.HonouredGuestMapper;
import com.tangyuan.user.service.IHonouredGuestService;
import com.tangyuan.vo.UserHonouredGuestVo;
import org.apache.ibatis.annotations.Mapper;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Description: honoured_guest
 * @Author: jeecg-boot
 * @Date:   2024-03-20
 * @Version: V1.0
 */
@Service
public class HonouredGuestServiceImpl extends ServiceImpl<HonouredGuestMapper, HonouredGuest> implements IHonouredGuestService {
    @Autowired
    HonouredGuestMapper honouredGuestMapper;
    @Autowired
    RedisTemplate redisTemplate;

    @Override
    public Result getMyHonouredGuest(Long userId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<UserHonouredGuestVo> list = honouredGuestMapper.getMyHonouredGuest(userId);
        return Result.ok(new PageInfo<>(list));
    }

    @Override
    public Result getMyActive(Long userId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<UserHonouredGuestVo> list = honouredGuestMapper.getMyActive(userId);
        return Result.ok(new PageInfo<>(list));
    }

    @Override
    public Result addHonouredGuest(UserHonouredGuestDto userHonouredGuestDto,Long userId) {
        userHonouredGuestDto.setUserId(userId);
        userHonouredGuestDto.setCreateTime(DateUtil.changeLocalDateTimeToDate(LocalDateTime.now()));
        honouredGuestMapper.addHonouredGuest(userHonouredGuestDto);
        return Result.ok();
    }

    @Override
    public Result addActive(UserHonouredGuestDto userHonouredGuestDto, Long userId) {
        userHonouredGuestDto.setUserId(userId);
        userHonouredGuestDto.setCreateTime(DateUtil.changeLocalDateTimeToDate(LocalDateTime.now()));
        honouredGuestMapper.addActive(userHonouredGuestDto);
        return Result.ok();
    }

    @Override
    public Result removeHonouredGuest(Integer id) {
        honouredGuestMapper.removeHonouredGuest(id);
        return Result.ok();
    }

    @Override
    public Result getMyHonouredGuestById(Integer id) {
        UserHonouredGuestVo userHonouredGuestVo = honouredGuestMapper.getMyHonouredGuestById(id);
        return Result.ok(userHonouredGuestVo);
    }
}
